package com.itheima.mapper;

import com.itheima.domain.Orders;
import com.itheima.domain.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
//映射配置类
public interface UserMapper {
    //查询所有
    @Select("select * from user")
    List<User> findAll();

    //根据id查询
    @Select("select * from user where id = #{uid}")
    User findById(int id);


    @Select("select * from user")
    @Results(id = "userMap",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(property = "ordersList",javaType = List.class,column = "id",
            many = @Many(select = "com.itheima.mapper.OrdersMapper.findByUid",fetchType = FetchType.LAZY))
    })
    List<User> findUserAndOrders();
}
